package deploy;

import common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.DataNode;
import server.NameNode;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

public class NNDeploy {
    private final int port;
    public NNDeploy(int PORT){
        this.port = PORT;
    }
    private static final Logger logger = LoggerFactory.getLogger(NNDeploy.class);
    void server() {
        try {
            System.setProperty("java.rmi.server.hostname", Utils.remoteIp);
            NameNode nn = new NameNode();
            LocateRegistry.createRegistry(port);
            String location = "//localhost"+":"+port+"/NN";
            Naming.rebind(location,nn);
            logger.info("NameNode start listen in {}",location);
        } catch (RemoteException | MalformedURLException e) {
            e.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        NNDeploy nameNode = new NNDeploy(30000);
//        nameNode.server();
//    }
}
